$("#head").load("header.html",function () {
})
$("#foot").load("footer.html",function () {})
$("#foot").load("footer.html",function () {})
new Vue({
    el:'#details',
    data:{
        d_title:"",
        d_source:"",
        d_content:"",
        d_hits:"",
        d_like:"",
        d_add_hits:"",
        d_add_like:"",
        d_comment_count:"",
        d_published_time:"",
        d_hitcount:"",
        //下一篇
        n_title:"",
        n_source:"",
        n_content:"",
        n_hits:"",
        n_like:"",
        n_add_hits:"",
        n_add_like:"",
        n_omment_count:"",
        n_published_time:"",
        n_hitcount:"",
        n_id:"",
    },
    ready:function(){
        var id = getUrlParam('id');
        var img_url = getUrlParam('img_url');
        var self=this;
        self.details(id);
        var height=$(window).height();
        $(".article-social ol a").eq(0).click(function () {
            $(".js-tutorials").show();
            $(".js-tutorials").css("height",height);
        })
        $(".article-social ol a").eq(2).click(function () {
            $(".js-tutorials").show();
            $(".js-tutorials").css("height",height);
        })
        $(".js-tutorials").click(function () {
            if($(".js-tutorials").is(':hidden')){
                $(".js-tutorials").show();
            }else{
                $(".js-tutorials").hide();
            }
        })
        $(".article-social ol a").eq(1).click(function () {
            var url = window.location.href;
            $(location).attr('href', 'http://service.weibo.com/share/mobile.php?url='+url+'&title='+self.n_title+'&pic='+img_url+'');
        })
    },
    methods:{
        details:function (id) {
            var self= this;
            var url="http://api.456mobi.com/api/?s=home/Information/detail";
            $.ajax({
                url :url,
                type : 'post',
                data : {
                    id:id,
                },
                success: function(ret){
                    self.d_title=ret.data[0].post_title;
                    self.d_source=ret.data[0].post_source;
                    self.d_content=self.unescape(ret.data[0].post_content);
                    self.d_hits=ret.data[0].post_hits;
                    self.d_like=ret.data[0].post_like;
                    self.d_add_hits=ret.data[0].add_hits;
                    self.d_add_like=ret.data[0].add_like;
                    self.d_comment_count=ret.data[0].comment_count;
                    self.d_published_time=self.timestampToTime_year(ret.data[0].published_time);
                    self.d_hitcount=ret.data[0].add_hits+ret.data[0].post_hits;
                    //下一篇
                    self.n_id = ret.data[1].id;
                    self.n_title=ret.data[1].post_title;
                    self.n_source=ret.data[1].post_source;4
                    self.n_content=self.unescape(ret.data[1].post_content);
                    self.n_hits=ret.data[1].post_hits;
                    self.n_like=ret.data[1].post_like;
                    self.n_add_hits=ret.data[1].add_hits;
                    self.n_add_like=ret.data[1].add_like;
                    self.n_comment_count=ret.data[1].comment_count;
                    self.n_published_time=self.timestampToTime_year(ret.data[1].published_time);
                    self.n_hitcount=ret.data[1].add_hits+ret.data[1].post_hits;
                }
            })
        },
        timestampToTime_year :function (timestamp) {
            var date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
            Y = date.getFullYear() + '-';
            M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
            D = date.getDate() + ' ';
            h = date.getHours() + ':';
            m = date.getMinutes() + ':';
            s = date.getSeconds();
            //return Y+M+D+h+m+s;
            return Y+M+D;
        },
        unescape:function (html) {
            return html
                .replace(html ? /&(?!#?\w+;)/g : /&/g, '&amp;')
                .replace(/&lt;/g, "<")
                .replace(/&gt;/g, ">")
                .replace(/&quot;/g, "\"")
                .replace(/&#39;/g, "\'");
        },
        next:function (id) {
            $(location).attr('href', 'news_details.html?id='+id);
        }
    }
});